import pymysql
from faker import Faker

fake = Faker(locale='zh_CN')
name = fake.name()
print(type(name))
print(f'insert into person (name,age,sex,country,job) values ("{name}",21,"女","蜀国",6)')

db = pymysql.connect(host='127.0.0.1',
                     port=3306,
                     user='root',
                     password='123!@#Qw',
                     database='wangzhe'
                     )

cs = db.cursor()
sql_insert = f'insert into person  values (default ,"{name}",21,"女","蜀国",6)'
sql_select = 'select * from person;'
sql_delete = f'delete from person  where name ="{name}"'
try:
    print(cs.execute(sql_insert))
    # print(cs.execute(sql_select))
    # data = cs.fetchone()
    # print(data)
    # data = cs.fetchone()
    # print(data)
    data = cs.fetchal3l()
    for i in data:
        print(i)
    # data = cs.fetchmany(2)
    # print(data)
    nums = cs.rowcount
    print(nums)
    print(cs.execute(sql_delete))
except:
    print("回滚事务")
    db.rollback()
finally:
    db.commit()
    cs.close()

db.close()
